package com.itlong.cloud.propertyapp.resource;

import com.itlong.cloud.POJO.DTO.app.property.app.PropertyAppDeviceInfoDTO;
import com.itlong.cloud.POJO.DTO.app.property.app.PropertyAppFeedbackInfoDTO;
import com.itlong.cloud.POJO.PO.PropertyRolePO;
import com.itlong.cloud.POJO.PO.PropertyUserInfoPO;
import com.itlong.cloud.POJO.VO.MessageVO;
import com.itlong.cloud.POJO.VO.app.AppGetQrcodeVO;
import com.itlong.cloud.POJO.VO.app.property.AppGetHouseholdCheckVO;
import com.itlong.cloud.POJO.VO.app.property.app.PropertyAppUserProjectInfoVO;
import com.itlong.cloud.POJO.VO.property.PropertyUserCacheVO;
import com.itlong.cloud.propertyapp.service.IPropertyAppUserInfoService;
import com.itlong.cloud.user.propertyapp.IPropertyAppUserInfoServiceClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <desc>
 *      物业app用户信息暴露接口实现类
 * </desc>
 *
 * @createDate2019/12/25
 **/
@RestController
public class PropertyAppUserInfoServiceResource implements IPropertyAppUserInfoServiceClient {

    @Autowired
    IPropertyAppUserInfoService iPropertyAppUserInfoService;
    /**
     * <desc>
     *      从缓存中读取用户信息
     * </desc>
     *
     * @param token
     * @return
     * @Author Zhu.yj
     * @createDate  2019/12/25
     */
    @Override
    @RequestMapping("/propertyapp/mine/retrieve")
    public PropertyUserCacheVO retrieve(@RequestParam("token") String token) {
        return iPropertyAppUserInfoService.retrieve(token);
    }

    /**
     * <desc>
     *      获取住户审核列表
     * </desc>
     *
     * @param projectId 项目编号
     * @return List<AppGetHouseholdCheckVO> 住户审核信息集
     * @Author Juguang.S
     * @createDate  2019/12/30
     */
    @Override
    @RequestMapping("/home/getHoldAuditList")
    public List<AppGetHouseholdCheckVO> getHoldAuditList(@RequestParam("projectId") String projectId){
        return iPropertyAppUserInfoService.getHoldAuditList(projectId);
    }

    /**
     * <desc>
     *      住户审核通过
     * </desc>
     *
     * @param projectId 项目编号
     * @param auditId   审核通过信息ID
     * @param type    1审核通过 2审核拒绝
     * @return
     * @Author Juguang.S
     * @createDate  2019/12/30
     */
    @Override
    @RequestMapping("/home/agreeHoldAudit")
    public Integer agreeHoldAudit(@RequestParam("projectId") String projectId,@RequestParam("auditId") String auditId,@RequestParam("type") String type){
        return iPropertyAppUserInfoService.agreeHoldAudit(projectId,auditId,type);
    }

    /**
     * <desc>
     *      登录查询验证
     * </desc>
     *
     * @param params 查询参数
     * @return 用户详细信息
     * @Author Zhu.yj
     * @createDate  2019/12/30
     */
    @Override
    @RequestMapping(value = "/mine/getPropertyUserInfo",method = RequestMethod.POST)
    public PropertyUserInfoPO getPropertyUserInfo(@RequestBody Map<String, Object> params) throws Exception {
        return iPropertyAppUserInfoService.getPropertyUserInfo(params);
    }

    /**
     * <desc>
     *      获取登录用户的项目列表
     * </desc>
     *
     * @param userId 用户id
     * @return projectMapList 包含pubKey,projectId,projectName
     * @Author Zhu.yj
     * @createDate  2019/12/30
     */
    @Override
    @RequestMapping(value = "/mine/getProjectListByUserId",method = RequestMethod.POST)
    public List<PropertyAppUserProjectInfoVO> getProjectListByUserId(@RequestParam("userId") String userId)throws Exception {
        return iPropertyAppUserInfoService.getProjectListByUserId(userId);
    }

    /**
     * <desc>
     *      更改密码
     * </desc>
     *
     * @param params 包含userId,password
     * @return
     * @Author Zhu.yj
     * @createDate  2019/12/31
     */
    @Override
    @RequestMapping(value = "/mine/updatePropertyUserPassword",method = RequestMethod.POST)
    public Integer updatePropertyUserPassword(@RequestBody Map<String, Object> params) throws Exception {
        return iPropertyAppUserInfoService.updatePropertyUserPassword(params);
    }

    /**
     * <desc>
     *      获取物业用户二维码
     * </desc>
     *
     * @param projectId 项目编号
     * @param userId 用户编号
     * @return AppGetQrcodeVO 返回app实体类
     * @Author Juguang.S
     * @createDate  2020/01/03
     */
    @Override
    @RequestMapping(value = "/pass/getPropertyAppUserQRcode",method = RequestMethod.POST)
    public AppGetQrcodeVO getPropertyAppUserQRcode(@RequestParam("projectId") String projectId,
                                                   @RequestParam("userId") String userId) throws Exception{
        return iPropertyAppUserInfoService.getPropertyAppUserQRcode(projectId,userId);
    }

    /**
     * <desc>
     *      处理物业用户未注册sip账号及未向灵云注册等问题
     * </desc>
     *
     * @param type 1为物业APP登录时调用 type 2为物业平台绑定手机号时调用
     * @Author Juguang.S
     * @createDate  2020/01/08
     */
    @Override
    @RequestMapping(value = "/pass/savePropertyUserSipInfo",method = RequestMethod.POST)
    public void savePropertyUserSipInfo (@RequestBody PropertyUserInfoPO userInfoPO,
                                         @RequestParam("projectId") String projectId,
                                         @RequestParam("type") Integer type) throws Exception{
        iPropertyAppUserInfoService.savePropertyUserSipInfo(userInfoPO,projectId,type);
    }

    /**
     * <desc>
     *      初始化 物业项目人员类型表中的基础数据 只调取一次
     * </desc>
     *
     * @author Jugaung.S
     * @createDate 2021/04/12
     */
    @Override
    @RequestMapping(value = "/pass/modifyPropertyUserTypeData",method = RequestMethod.POST)
    public void modifyPropertyUserTypeData(){
        iPropertyAppUserInfoService.modifyPropertyUserTypeData();
    }

    /**
     * <desc>
     *      退出登录
     * </desc>
     *
     * @param userId 用户id
     * @return
     * @Author Zhu.yj
     * @createDate  2020/1/9
     */
    @Override
    @PostMapping("mine/loginOut")
    public boolean loginOut(@RequestParam("userId") String userId) throws Exception {
        return iPropertyAppUserInfoService.loginOut(userId);
    }

    /**
     * <desc>
     *      物业APP用户上传设备排序
     * <desc/>
     *
     * @param propertyAppDeviceInfoDTO 设备排序相关数据
     * @return
     * @author Juguang.S
     * @createDate 2020-01-09
     */
    @Override
    @RequestMapping(value = "/pass/upLoadAllSort",method = RequestMethod.POST)
    public Integer upLoadAllSort(@RequestBody PropertyAppDeviceInfoDTO propertyAppDeviceInfoDTO) throws Exception{
        return iPropertyAppUserInfoService.upLoadAllSort(propertyAppDeviceInfoDTO);
    }

    /**
     * <desc>
     *      物业APP用户上传组设备排序
     * <desc/>
     *
     * @param propertyAppDeviceInfoDTO 组设备排序相关数据
     * @return
     * @author Juguang.S
     * @createDate 2020-01-09
     */
    @Override
    @RequestMapping(value = "/pass/deviceGroupSort",method = RequestMethod.POST)
    public Integer deviceGroupSort(@RequestBody PropertyAppDeviceInfoDTO propertyAppDeviceInfoDTO) throws Exception{
        return iPropertyAppUserInfoService.deviceGroupSort(propertyAppDeviceInfoDTO);
    }

    /**
     * <desc>
     *      更改头像或别名
     * </desc>
     *
     * @param params 更新参数包含 用户id和头像或别名
     * @return
     * @Author Zhu.yj
     * @createDate  2020/1/10
     */
    @Override
    @PostMapping("/mine/updatePhotoOrName")
    public Integer updatePhotoOrName(@RequestBody Map<String, Object> params) throws Exception {
        return iPropertyAppUserInfoService.updatePhoto(params);
    }

    /**
     * <desc>
     *      登陆缓存用户信息
     * </desc>
     *
     * @param propertyUserInfoPO 物业用户信息PO
     * @param loginDevice 登录设备 1安卓 2苹果
     * @return
     * @Author Zhu.yj
     * @createDate  2020/1/14
     */
    @Override
    @PostMapping("/mine/loginCacheUser")
    public Map<String, Object> loginCacheUser(@RequestBody PropertyUserInfoPO propertyUserInfoPO, @RequestParam("loginDevice") String loginDevice) throws Exception {
        return iPropertyAppUserInfoService.loginCacheUser(propertyUserInfoPO,loginDevice);
    }

    /**
     * <desc>
     *      获取通行记录列表信息
     * </desc>
     *
     * @param projectId 项目id
     * @param pageIndex
     * @param userId
     * @return
     * @Author Zhu.yj
     * @createDate  2020/1/14
     */
    @Override
    @PostMapping("/mine/getPassRecordPage")
    public Map<String, Object> getPassRecordPage(@RequestParam("projectId") String projectId,
                                                 @RequestParam("pageIndex") String pageIndex,
                                                 @RequestParam("userId") String userId) throws Exception {
        return iPropertyAppUserInfoService.getPassRecordPage(projectId,pageIndex,userId);
    }

    /**
     * <desc>
     *      保存反馈信息
     * </desc>
     *
     * @param propertyAppFeedbackInfoDTO 物业app反馈信息DTO
     * @return 受影响行数
     * @Author Zhu.yj
     * @createDate  2020/1/15
     */
    @Override
    @PostMapping("/mine/saveFeedback")
    public Integer saveFeedback(@RequestBody PropertyAppFeedbackInfoDTO propertyAppFeedbackInfoDTO) throws Exception {
        return iPropertyAppUserInfoService.saveFeedback(propertyAppFeedbackInfoDTO);
    }

    /**
     * <desc>
     *      查询历史反馈信息
     * </desc>
     *
     * @param userId 用户id
     * @param projectId 项目id
     * @param pageNum 页码
     * @return
     * @Author Zhu.yj
     * @createDate  2020/1/15
     */
    @Override
    @PostMapping("/mine/getHistoryFeedback")
    public Map<String,Object> getHistoryFeedback(@RequestParam("userId") String userId,
                                                              @RequestParam("projectId") String projectId,
                                                              @RequestParam("pageNum")String pageNum) throws Exception {
        return iPropertyAppUserInfoService.getHistoryFeedback(userId,projectId,pageNum);
    }

    /**
     * <desc>
     *      上传常用楼层
     * </desc>
     *
     * @param projectId       项目编号
     * @param deviceUnique    设备序列号
     * @param loadDeviceOrder 常用楼层名称
     * @param userId 用户id
     * @return 1成功，0失败
     * @author Juguang.S
     * @createDate 2020/01/15
     */
    @Override
    @RequestMapping(path = "/mine/uploadChoiceFloor")
    public Integer uploadChoiceFloor(@RequestParam("projectId") String projectId,
                                     @RequestParam("deviceUnique") String deviceUnique,
                                     @RequestParam("loadDeviceOrder") String loadDeviceOrder,
                                     @RequestParam("userId") String userId) throws Exception {
        return iPropertyAppUserInfoService.uploadChoiceFloor(projectId, deviceUnique, loadDeviceOrder, userId);
    }

    /**
     * <desc>
     *      检查当前账号是否被锁定
     * </desc>
     *
     * @param accountNo 登录账号
     * @return
     * @Author Zhu.yj
     * @createDate  2020/2/27
     */
    @Override
    @PostMapping("/mine/getPropertyAppAccountLockDetail")
    public MessageVO getPropertyAppAccountLockDetail(@RequestParam("accountNo") String accountNo) throws Exception {
        return iPropertyAppUserInfoService.getPropertyAppAccountLockDetail(accountNo);
    }

    /**
     * <desc>
     *      物业app登录错误处理
     * </desc>
     *
     * @param accountNo 登录账号
     * @return
     * @Author Zhu.yj
     * @createDate  2020/2/27
     */
    @Override
    @PostMapping("/mine/propertyAppLoginErrorHandler")
    public MessageVO propertyAppLoginErrorHandler(@RequestParam("accountNo") String accountNo) throws Exception {
        return iPropertyAppUserInfoService.propertyAppLoginErrorHandler(accountNo);
    }

    /**
     * <desc>
     *      获取物业角色详细信息
     * </desc>
     *
     * @param roleId 角色id
     * @return
     * @Author Zhu.yj
     * @createDate  2020/3/2
     */
    @Override
    @PostMapping("/mine/getPubTypeByRole")
    public List<PropertyRolePO> getPubTypeByRole(@RequestParam("roleId") String roleId) throws Exception {
        return iPropertyAppUserInfoService.getPubTypeByRole(roleId);
    }

    /**
     * <desc>
     *      根据userId获取第三方token
     * </desc>
     *
     * @param userId 用户id
     * @return
     * @Author Zhu.yj
     * @createDate  2020/3/2
     */
    @Override
    @PostMapping("/mine/getUserClientToken")
    public String getUserClientToken(@RequestParam("userId") String userId) throws Exception {
        return iPropertyAppUserInfoService.getUserClientToken(userId);
    }

    /**
     * <desc>
     *      物业APP用户设置分组名称
     * <desc/>
     *
     * @param propertyAppDeviceInfoDTO 分组ID
     * @return
     * @author Juguang.S
     * @createDate 2020-01-09
     */
    @Override
    @RequestMapping(value = "/pass/setDeGroupName",method = RequestMethod.POST)
    public Integer setDeGroupName(@RequestBody PropertyAppDeviceInfoDTO propertyAppDeviceInfoDTO) throws Exception{
        return iPropertyAppUserInfoService.setDeGroupName(propertyAppDeviceInfoDTO);
    }

    /**
     * <desc>
     *      根据手机号获取物业用户信息
     * </desc>
     *
     * @param phoneNo
     * @return
     * @Author Zhu.yj
     * @createDate  2020/3/12
     */
    @Override
    @PostMapping(value = "/propertyapp/user/getByAccount")
    public PropertyUserInfoPO getByAccount(@RequestParam("phoneNo") String phoneNo) throws Exception {
        return iPropertyAppUserInfoService.getByAccount(phoneNo);
    }

    /**
     * <desc>
     *      更新用户当前项目id
     * </desc>
     *
     * @param projectId 项目id
     * @param userId 用户id
     * @return
     * @Author Zhu.yj
     * @createDate  2020/3/16
     */
    @Override
    @PostMapping(value = "user/updateCurrentProjectId")
    public Integer updateCurrentProjectId(@RequestParam("projectId") String projectId,@RequestParam("userId") String userId) throws Exception {
        return iPropertyAppUserInfoService.updateCurrentProjectId(projectId,userId);
    }

    /**
     * <desc>
     *      根据deviceUnique查询居住楼层集合使用于物业APP
     * </desc>
     *
     * @param deviceUnique 设备唯一码
     * @return
     * @Author Juguang.S
     * @createDate  2020/04/16
     */
    @Override
    @RequestMapping(value = "/pass/getLiveFloorByDeviceUnique",method = RequestMethod.POST)
    public List<String> getLiveFloorByDeviceUnique(@RequestParam("deviceUnique") String deviceUnique){
        return iPropertyAppUserInfoService.getLiveFloorByDeviceUnique(deviceUnique);
    }


}
